package com.gxa.ssm340.controller;

import com.gxa.ssm340.common.R;
import com.gxa.ssm340.common.Render;
import com.gxa.ssm340.entity.dto.*;
import com.gxa.ssm340.entity.pojo.Manager;
import com.gxa.ssm340.entity.vo.AdminMenusVO;
import com.gxa.ssm340.entity.vo.ManagerPageVO;
import com.gxa.ssm340.entity.vo.PointGetVO;
import com.gxa.ssm340.exception.BizException;
import com.gxa.ssm340.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 管理员控制器
 * @author 赵文川
 * @Description: $
 * @date 2023/10/20 19:43
 */
@RestController
public class AdminController {

    @Autowired
    private AdminService adminService;
/**
 * @Description: admin登录
 * @param adminLoginDTO
 * @return: com.gxa.ssm340.common.R
 * @Author: 易某
 * @Date: 2023/10/25 10:16
 */
    @PostMapping("/admin/login")
    public R login(AdminLoginDTO adminLoginDTO) throws BizException {
        AdminMenusVO adminMenusVO = adminService.AdminLogin(adminLoginDTO);
        System.out.println(adminMenusVO);
        return R.success(adminMenusVO,1);
    }

    @PostMapping("/mgr/add")
    public R addManager(@RequestBody ManagerRegDTO dto) throws BizException {
        System.out.println(dto.toString());
        adminService.addManager(dto);
        return R.success();
    }

    @GetMapping("/mgr/getList")
    public Render getManagerList(ManagerPageDTO dto) throws BizException {
        ManagerPageVO managers = adminService.getManagers(dto);
        return Render.success(managers.getManagers(),managers.getCount());
    }

    @PostMapping("/mgr/delete")
    public R dropManager(@RequestBody Manager manager) throws BizException {
        adminService.removeManager(manager.getPhone());
        return R.success();
    }

    @PostMapping("/mgr/update")
    public R modifyManagerIsUse(ManagerIsUseDTO dto) throws BizException {
        adminService.modifyManagerIsUse(dto);
        return R.success();
    }

    @GetMapping("/admin/pointsGetList")
    public Render getIncomePointList(PointGetDTO dto) throws BizException {
        PointGetVO incomePoints = adminService.getIncomePoints(dto);
        return Render.success(incomePoints.getPoints(),incomePoints.getCount());
    }

}
